<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">

<title>Dashboard Template for Bootstrap</title>

<!-- Bootstrap core CSS -->
<link href="/libs/bootstrap/4.0/css/bootstrap.min.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="/libs/bootstrap/4.0/css/dashboard.css" rel="stylesheet">
</head>

<body>
	<div id="header"></div>
	<div class="container-fluid">
		<div class="row">
			<div id="menu"></div>

			<main class="col-sm-9 offset-sm-3 col-md-10 offset-md-2 pt-3">
			<form class="form-inline" role="form">
				<div class="col-lg-2">
					<div class="input-group">
						<input type="text" class="form-control" id="queryCode"> <span
							class="input-group-btn">
							<button class="btn btn-default" type="button" id="queryAction">
								Go!</button>
						</span>
					</div>
				</div>
				<div class="checkbox">
					<label> <input type="checkbox" id="yearRptOnly"
						name="yearRptOnly">只看年报
					</label>
				</div>
				<div class="checkbox">
					<label> &nbsp;<a href="#" id="updateRpt">更新业绩</a> <span
						id="updateRptTip">后台正在获取数据...</span> <span id="updateRptTipSucc">更新成功！</span>
					</label>
				</div>
			</form>
			<div class="row">
				<div id="rptList" style="width: 45%; hight: 100%; float: left；">
					<table class="table table-hover" id="cusTable">
					</table>
				</div>
				<div style="width: 45%; hight: 100%; float: left；">
					<div id="rptAnaly"></div>
					<div id="rptAnalyNof">
						<span id="showTips2">正在分析,过程需要一段时间...</span>
					</div>
				</div>
			</div>
			</main>
		</div>
	</div>

	<!-- Bootstrap core JavaScript
    ================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->
	<script src="/libs/js/jquery-3.1.1.slim.min.js"
		integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n"
		crossorigin="anonymous"></script>
	<script src="/libs/js/tether.min.js"
		integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb"
		crossorigin="anonymous"></script>
	<script src="/libs/bootstrap/4.0/js/bootstrap.min.js"></script>
	<script src="/libs/js/common.js"></script>
	<script src="/libs/js/jquery.js"></script>
	<script src="/libs/js/dashboard/index.js"></script>
	<script src="/libs/bootstrap/4.0/js/bootstrap-table.js"></script>

	<script type="text/javascript">
		var lihao = "<br/>利好=>";
		var likong = "<br/><br/>利空=>";
		var zhongxing = "<br/><br/>中性=>";
		$("#rptAnaly").hide();
		$("#rptAnalyNof").hide();
		$("#showTips2").hide();
		function showAanlyinces(reload) {
			$("#rptAnalyNof").hide();
			$("#rptAnaly").hide();
			$("#rptAnaly").html("");
			$("#showTips2").hide();
			$.ajax({url : '/ui/stockReports/showRptsAnalyze',
						type : 'GET', // GET
						async : true, // 或false,是否异步
						data : {code : $.trim($("#queryCode").val())},
						dataType : 'json', // 返回的数据格式：json/xml/html/script/jsonp/text
						success : function(data, textStatus, jqXHR) {
							if ("00000000" == data.rtnCode) {
								if ('NotFound' != data.bizData) {
									var html = "";
									var clh = 0;
									var clk = 0;
									var czx = 0;
									//lihao
									if (data.bizData.starBreakPoint > 0) {
										clh++;
										html += lihao;
										html += "<br/>业绩拐点至盈利，拐点指数："
												+ data.bizData.starBreakPoint
									}
									if (data.bizData.starIncreaseUp > 0) {
										if (clh == 0) {
											clh++;
											html += lihao;
										}
										html += "<br/>业绩稳步增长,增长指数："
												+ data.bizData.starIncreaseUp
									}
									if (data.bizData.profitJiduOnJidu == -1) {
										if (clh == 0) {
											clh++;
											html += lihao;
										}
										html += "<br/>季度业绩环比：扭亏！"
									} else if (data.bizData.profitJiduOnJidu != 0.0) {
										if (clh == 0) {
											clh++;
											html += lihao;
										}
										html += "<br/>季度业绩环比增长："
												+ data.bizData.profitJiduOnJidu + "%"
									}
									//zhognxing
									if (data.bizData.profitYearOnYear > 0.0) {
										if (czx == 0) {
											czx++;
											html += zhongxing;
										}
										html += "<br/>2年业绩同比指数："+data.bizData.profitYearOnYear
									}									
									if (data.bizData.profit3YearInc) {
										if (czx == 0) {
											czx++;
											html += zhongxing;
										}
										html += "<br/>最近3年赚钱放大！"
									}
									if (data.bizData.profit2Year) {
										if (czx == 0) {
											czx++;
											html += zhongxing;
										}
										html += "<br/>最近2年没有亏！"
									}
									//likong
									if (data.bizData.maybeSt) {
										if (clk == 0) {
											clk++;
											html += likong;
										}
										html += "<br/>连续2年亏损，存在<span style='font-color:red'>ST风险</span>"
									}
									if (data.bizData.starBreakPointB > 0) {
										if (clk == 0) {
											clk++;
											html += likong;
										}
										html += "<br/>业绩拐点至亏损，拐点指数："
												+ data.bizData.starBreakPointB
									}
									if (data.bizData.starIncreaseUpB > 0) {
										if (clk == 0) {
											clk++;
											html += likong;
										}
										html += "<br/>业绩稳步萎缩,萎缩指数："
												+ data.bizData.starIncreaseUpB
									}
									if (data.bizData.profit3YearIncB) {
										if (clk == 0) {
											clk++;
											html += likong;
										}
										html += "<br/>最近3年赚钱逐步减少！"
									}

									$("#rptAnaly").html(html);
									$("#rptAnaly").show();
								} else {
									$("#rptAnalyNof").show();
								}
							} else {
								alert("获取失败!");
							}
						},
						error : function(xhr, textStatus) {
							console.log(xhr)
							console.log(textStatus)
							alert("系统异常2");
						}
					});
		}

		$("#header").load("/header.html")
		$("#menu").load("/menu.html")
		$("#updateRptTip").hide();
		$("#updateRptTipSucc").hide();
		addActive("m_reports_analytics");
		$('#cusTable').bootstrapTable('destroy');
		$("#updateRpt").click(function() {
			var code = $.trim($("#queryCode").val());
			if (code == "") {
				alert("null code");
				return;
			}
			$("#updateRptTip").show();
			$("#updateRpt").hide();
			$("#updateRptTipSucc").hide();
			$.ajax({
				url : '/ui/stockReports/getRptsFormNet',
				type : 'GET', // GET
				async : true, // 或false,是否异步
				data : {
					code : code
				},
				dataType : 'json', // 返回的数据格式：json/xml/html/script/jsonp/text
				success : function(data, textStatus, jqXHR) {
					if ("00000000" == data.rtnCode) {
						$("#updateRpt").show();
						$("#updateRptTipSucc").show();
						$("#updateRptTip").hide();

						$("#queryAction").click();
						setTimeout("$('#updateRptTipSucc').hide()", 3000);
					} else {
						alert("更新失败!");
						$("#updateRpt").show();
						$("#updateRptTip").hide();
						$("#updateRptTipSucc").hide();
					}
				},
				error : function(xhr, textStatus) {
					console.log(xhr)
					console.log(textStatus)
					alert("系统异常1");
					$("#updateRpt").show();
					$("#updateRptTip").hide();
					$("#updateRptTipSucc").hide();
				}
			});
		});
		$("#queryAction").click(
						function() {
							var code = $.trim($("#queryCode").val());
							if (code == "") {
								alert("null code");
								return;
							}
							var yearRptOnly = $("#yearRptOnly").prop('checked');
							$('#cusTable').bootstrapTable('destroy');
							$("#cusTable")
									.bootstrapTable(
											{
												method : "get", //使用get请求到服务器获取数据  
												url : "/ui/stockReports/queryRpts", //获取数据的Servlet地址  
												striped : true, //表格显示条纹  
												pagination : true, //启动分页
												cache : false,
												pageSize : 10, //每页显示的记录数  
												//pageNumber:1, //当前第几页  
												pageList : [ 10, 15, 20, 50 ], //记录数可选列表  
												search : false, //是否启用查询  
												//showColumns: true,  //显示下拉框勾选要显示的列  
												//showRefresh: true,  //显示刷新按钮  
												sidePagination : "server", //表示服务端请求
												//设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder  
												//设置为limit可以获取limit, offset, search, sort, order  
												queryParamsType : "undefined",
												queryParams : function queryParams(
														params) { //设置查询参数  
													var param = {
														pageNo : params.pageNumber,
														pageSize : params.pageSize,
														code : code,
														yearRptOnly : yearRptOnly
													};
													return param;
												},
												columns : [
														{
															field : 'code',
															title : '代码'
														},
														{
															field : 'date',
															title : '日期',
															formatter : function(
																	value, row,
																	index) {
																return formDate(value);
															}
														},
														{
															field : 'income',
															title : '营收'
														},
														{
															field : 'profit',
															title : '利润',
															formatter : function(
																	value, row,
																	index) {
																if ((formDate(row.date) + "")
																		.endsWith("12-31")) {
																	return value
																			+ "&nbsp;&nbsp;&nbsp;&nbsp;<span style='background-color: #d9534f'>年报</span>";
																}
																return value;
															}
														} ],
												responseHandler : function responseHandler(
														res) {
													//alert(res.bizData);
													var s1 = JSON
															.stringify(res.bizData.list);
													var s2 = '{"total":'
															+ res.bizData.total
															+ ',"rows":' + s1
															+ '}';
													//alert(s2);
													return eval('(' + s2 + ')')
												},
												rowStyle : function(row, index) {
													////按需求设置不同的样式：5个取值代表5中颜色['active', 'success', 'info', 'warning', 'danger'];
													var fdStart = row.profit
															.indexOf("-");
													if (fdStart == 0) {
														var style = {
															css : {
																'background-color' : '#ed5565'
															}
														};
														return style;
													} else {
														return {};
													}
													//<span class="label label-default">年报</span>
												},
												onLoadSuccess : function() { //加载成功时执行
													$("#rptList").show();
													showAanlyinces(false);
												},
												onLoadError : function() { //加载失败时执行  
													alert("加载数据失败");
												}
											});
						});
		
		var qcode = getQueryString("code");
		if(qcode!=null){
			$("#queryCode").val(qcode)
			$("#queryAction").click();
		}
	</script>
</body>
</html>
